var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2AudioManager = require("AudioManager");
var $2BulletMgr = require("BulletMgr");
var $2BundleManager = require("BundleManager");
var $2DataManager = require("DataManager");
var $2ZombieMgr = require("ZombieMgr");
var $2SceneStage = require("SceneStage");
var $2KDefine = require("KDefine");
var $2BulletBase = require("BulletBase");
var $2PlantBase = require("PlantBase");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_Plant9 = /* */function (_u$default4) {
  babel_inherits(f, _u$default4);
  var _super71 = babel_createSuper(f);
  function f() {
    var _this154;
    babel_classCallCheck(this, f);
    _this154 = _super71.apply(this, arguments);
    _this154.row2 = 9;
    return _this154;
  }
  babel_createClass(f, [{
    key: "shoot",
    value: function shoot() {
      var _this155 = this;
      var e = this;
      if (null == this.getZombie()) {
        return void e.setState($2KDefine.State.wait);
      }
      var t = this.getZombie().x - 80;
      var a = this.getZombie().y;
      if (0 == this.remainCD) {
        var _n40 = this.dragon.setAnimation(0, "dazhao", true);
        var _i12 = 0;
        this.dragon.setCompleteListener(function () {
          if (++_i12 == _this155.skillNums) {
            e.setState($2KDefine.State.wait);
            _this155.attackTimes += _this155.attackCD;
            _this155.remainCD = _this155.skillCD;
          }
        });
        this.dragon.setTrackEventListener(_n40, function (e, n) {
          if ("dazhao" == n.data.name) {
            var _e77 = _this155.getZombie(2 * _i12);
            null == _e77 && (_e77 = new cc.Vec2(330, $2DataManager.default.instance.groudYArr[2 * _i12]));
            t = _e77.x;
            a = _e77.y;
            _this155.attack(t, a, true);
          }
        });
      } else {
        this.dragon.setCompleteListener(function () {
          e.setState($2KDefine.State.wait);
        });
        this.attackTimes += this.attackCD;
        var _n41 = this.dragon.setAnimation(0, "gongji", false);
        this.dragon.setTrackEventListener(_n41, function (e, n) {
          "gongji" == n.data.name && _this155.attack(t, a);
        });
      }
    }
  }, {
    key: "attack",
    value: function attack(e, t) {
      var a = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
      var n;
      var l = new cc.Vec2(this.node.getPosition().x + this.shootPo.x, this.node.getPosition().y + this.shootPo.y);
      if (a) {
        n = $2BulletMgr.default.instance().getItem(this.skillbullet, this.damage, this.hitSound, this.hitSoundVolume).node;
        $2AudioManager.default.instance.playEffect(this.skillSound, this.skillSoundVolume);
      } else {
        n = $2BulletMgr.default.instance().getItem(this.bulletId, this.damage, this.hitSound, this.hitSoundVolume).node;
        $2AudioManager.default.instance.playEffect(this.shootSound, this.shootSoundVolume);
      }
      n.angle = 18;
      n.getComponent(cc.CircleCollider).enabled = false;
      n.parent = $2SceneStage.default.instance.groudNode;
      n.setPosition(l);
      n.zIndex = $2KDefine.ZIndex.bullet;
      n.opacity = 255;
      cc.tween(n).by(1 / (5 * this.attackSpeed), {
        y: 650
      }).delay(1 / this.attackSpeed).call(function () {
        n.x = e;
        n.angle = 0;
      }).to(1 / this.attackSpeed, {
        y: t
      }).call(function () {
        var e = n.getChildByName("bulletEffect").getComponent(sp.Skeleton);
        n.getComponent(cc.CircleCollider).enabled = true;
        n.getChildByName("bulletEffect").active = true;
        n.getComponent(cc.Sprite).enabled = false;
        e.skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "effect/" + n.getComponent($2BulletBase.default).bulletEffect + "/" + n.getComponent($2BulletBase.default).bulletEffect, sp.SkeletonData);
        e.setAnimation(0, "newAnimation", false);
        e.setCompleteListener(function () {
          n.getChildByName("bulletEffect").active = false;
          $2BulletMgr.default.instance().removeBullet(n.getComponent($2BulletBase.default));
          e.setCompleteListener(null);
        });
      }).start();
    }
  }, {
    key: "getZombie",
    value: function getZombie(e) {
      var _this156 = this;
      var t = 99999;
      var a = null;
      var _loop5 = function _loop5(_n42) {
        _n42 != e && e || $2ZombieMgr.default.instance().zombieInRow[_n42].size <= 0 || $2ZombieMgr.default.instance().zombieInRow[_n42].forEach(function (e) {
          var i = e.node.x;
          if (i < t) {
            t = i;
            a = e.node;
            _this156.row2 = _n42;
          }
        });
      };
      for (var _n42 = 0; _n42 < $2ZombieMgr.default.instance().zombieInRow.length; _n42++) {
        _loop5(_n42);
      }
      if (null == a) {
        if (e) {
          return new cc.Vec2(330, $2DataManager.default.instance.groudYArr[e]);
        } else {
          return null;
        }
      } else {
        return a.getPosition();
      }
    }
  }, {
    key: "checkTarget",
    value: function checkTarget() {
      return 0 != $2ZombieMgr.default.instance().zombieNums;
    }
  }]);
  return f;
}($2PlantBase.default);
def_Plant9 = cc__decorate([ccp_ccclass], def_Plant9);
exports.default = def_Plant9;